//
//  BaseViewController.swift
//  DWater-Swift
//
//  Created by mac on 2017/4/18.
//  Copyright © 2017年 Dimon.胡亚宾. All rights reserved.
//

import UIKit

@objc public protocol BaseViewControllerDelegate {
      func didBackBtn()
}
class BaseViewController: UIViewController {
    public func didBackBtn() {
        delegate?.didBackBtn()

    }
    var delegate:BaseViewControllerDelegate?
    var naviBar : BaseNaviBar?
    

    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    func didSelectBackButton(sender:UIButton) -> () {
        self.navigationController?.popViewController(animated: true)
        delegate?.didBackBtn()
 
    }
    
    func setDefaultBackBtn(title:NSString) -> () {
        
        let backBtton = UIButton(type:.custom)
        backBtton.frame = CGRect(x: 0, y: 0, width: 200, height: 50)
        backBtton.backgroundColor = UIColor.clear
        backBtton.contentHorizontalAlignment = .left
        backBtton.setImage(UIImage.init(named: "base_nav_back"), for: .normal)
        backBtton.setTitle("\(title)", for: .normal)
        backBtton.titleLabel?.font = UIFont.systemFont(ofSize: 16)
        backBtton.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0)
        backBtton.addTarget(self, action: #selector(didSelectBackButton(sender: )), for: .touchUpInside)
        self.naviBar?.leftView = backBtton
        self.naviBar?.backButton = backBtton
        
    }
    
    
    func setRightButton(title:NSString) -> () {
        let exitButton = UIButton(type:.custom)
        exitButton.frame = CGRect(x: SCREEN_WIDTH - 100, y: 0, width: 90, height: 50)
        exitButton.backgroundColor = UIColor.clear
        exitButton.contentHorizontalAlignment = .right
        exitButton.setTitle("  \(title)", for: .normal)
        exitButton.titleLabel?.font = UIFont.systemFont(ofSize: 16)
        self.naviBar?.rightView = exitButton

    }
    
   
    
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
